<?php
	include_once "isLogin.php";
	$adminc = new admin();
	$action = $_GET['action'];

	//删除批量
	if('del' == $action){
		$ids = $_POST['id'];
		$res = $adminc->adminDel($ids, 'id'); 
		die($res);
	}

	//ajax 动态修改
	if('edit' == $action){
		$name_id = $_POST['name_id'];
		$name = $_POST['name'];
		$arr = array('name' => $name);
		$res = $adminc->adminUpdate($arr, ' id = "'.$name_id.'"');
		die($res);
	}

	$where = '';
	if($_GET['name'] != ''){
		$where .= ' AND name like "%'.$_GET['name'].'%"';
	}
	if($_GET['flag'] != ''){
		$where .= ' AND flag ="'.$_GET['flag'].'"';
	}
	$smarty->assign("search" ,$_POST);

	$admins = $adminc->adminList($where,'*', 1);

	if($_GET['action'] == 'list'){
		if(is_array($admins['result'])){
			foreach($admins['result'] as $k => $v){
				$admins['result'][$k]['action'] = '<a href="example_edit.php?id='.$v['id'].'">修改</a>';
			}
		}
		echo json_encode($admins['result']);
		exit();
	}

	$smarty->assign("admins" ,$admins['result']);
	$smarty->assign("page" ,$admins['page']);

	$smarty->display('example_list.html');
?>